package tdd.kata.day1;

/** @author robin */
public class Day1 {
  int[] depths;

  public Day1(int[] depths) {
    this.depths = depths;
  }

  public int countDepthIncreases() {
    int count = 0;
    for (int i = 1; i < depths.length; i++) {
      if (ifIncreases(depths[i - 1], depths[i])) {
        count++;
      }
    }
    return count;
  }

  private boolean ifIncreases(int previous, int following) {
    return following > previous;
  }

  public int getThreeMeasurementWindowSize() {
    if (depths.length < 2) {
      return 0;
    }
    return depths.length - 2;
  }

  public int countDepthIncreasesOfThreeMeasurementWindow() {
    if (getThreeMeasurementWindowSize() < 2) {
      return 0;
    }
    return countDepthIncreasesByThreeMeasurementWindow();
  }

  private int countDepthIncreasesByThreeMeasurementWindow() {
    int count = 0;
    for (int i = 3; i < depths.length; i++) {
      if (ifIncreases(
          (depths[i - 3] + depths[i - 2] + depths[i - 1]),
          (depths[i - 2] + depths[i - 1] + depths[i]))) {
        count++;
      }
    }
    return count;
  }
}
